﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
using RedBit.UserVoice.Model;
using RedBit.UserVoice.Helpers;
using RedBit.UserVoice.Services;

namespace SampleApplication
{
    public partial class CommentPage : PhoneApplicationPage
    {
        private string m_suggestionId = "";
        private string m_forumId = "";

        public CommentPage()
        {
            InitializeComponent();
        }

        private void cbSave_Click(object sender, EventArgs e)
        {
            var comment = new UVComment
            {
                CreatedAt = DateTime.Now,
                Text = tbComment.Text,
                User = UVUserHelper.CurrentUser
            };

            UVCommentService.CommentOnSuggestion(m_forumId, m_suggestionId, comment, response => HandleResponse(response));
        }

        private void HandleResponse(UVResponse<UVComment> response)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() => NavigationService.GoBack());
        }

        private void cbCancel_Click(object sender, EventArgs e)
        {
            NavigationService.GoBack();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            NavigationContext.QueryString.TryGetValue("suggestionId", out m_suggestionId);
            NavigationContext.QueryString.TryGetValue("forumId", out m_forumId);

            
        }

    }
}